function btnLogin_onclick()
{
    var argsArray=new Array();
    argsArray.push(newArg("action","login"));
    var userName=document.getElementById("user").value;
    argsArray.push(newArg("user",userName));
    var password=document.getElementById("password").value;
    argsArray.push(newArg("password",hex_md5(password)));
    argsArray.join("&");

    if(userName != "" && password!= "")
        sendRequest("../controller/login.jsp",argsArray,btnLogin_response);
    else
        jConfirm('Faltan datos por llenar','Error', 'Error Dialog');
    
}

function clear_fieldsL(){
    document.getElementById("user").value="";
    document.getElementById("password").value="";
}

function btnLogin_response()
{
    if (isValidResponse(this))
    {
        var res=this.responseText;
        if(res!="")
        {
            var info=eval("("+res+")");
            if(info.errorcode == 0){
                //jAlert('Succesfull','Ok', 'Success Dialog');
                //document.getElementById("loged").style.display = "block";
                //document.getElementById("loged").innerHTML = "";
                //var buttonLogout = "<input type=\"button\" id=\"logoutUser\" value=\"Cerrar Sesión\" class=\"button_form\" onclick=\"btnLogout_onclick()\">";
                //document.getElementById("loged").innerHTML = info.user_uname + "<span>&nbsp; &nbsp; | &nbsp; &nbsp;</span>" + buttonLogout;
                clear_fieldsL();
                //window.location = "../index.jsp";
                window.parent.location.reload();
            }
            else if(info.errorcode == -1)
                jConfirm('Error con la Base de Datos','Error', 'Error Dialog');
            else if(info.errorcode == -3)
                jConfirm('Usuario no encontrado','Error', 'Error Dialog');
            else
                jConfirm('Acceso Incorrecto','Error', 'Error Dialog');
        }
    }
}

function btnLogout_onclick()
{
    var argsArray=new Array();
    argsArray.push(newArg("action","logout"));    
    argsArray.join("&");
    sendRequest("controller/login.jsp",argsArray,btnLogout_response);
}

function btnLogout_response()
{
    if (isValidResponse(this))
    {
        var res=this.responseText;
        if(res!="")
        {
            var info=eval("("+res+")");
            if(info.errorcode == 0){
                //window.location = "../view/travelMap.jsp";
                window.parent.location.reload();
            }
            else if(info.errorcode == -1)
                jConfirm('Sesión no encontrada','Error', 'Error Dialog');
            else
                jConfirm('Acceso Incorrecto','Error', 'Error Dialog');
        }
    }
}
